package com.wink.common;

import java.util.Date;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.google.gson.Gson;
//import com.wink.common.Identity;
import com.wink.service.CommunityServicesImpl;

@XmlRootElement(name = "login")
@XmlAccessorType(XmlAccessType.FIELD)
public class Login {	

	@XmlElement(name = "name")
	private String name;	
	
	@XmlElement(name = "password")
	private String password;
	
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	public String toString() {
		StringBuffer sf = new StringBuffer();
		
		sf.append("<name> " + name);
		sf.append("<password> " + password);						
		return sf.toString();
	}
	
	public static String toJson(Login login) {
		Gson gson = new Gson();
		String json = gson.toJson(login, Login.class);
		System.out.println("---> login: tojson  " + json);
		
		Login retCh = gson.fromJson(json, Login.class);
		return json;
	}
	
	public static Login fromJson(String json) {
		Gson gson = new Gson();
		Login retCh = gson.fromJson(json, Login.class);
		System.out.println("---> Chairty: fromJson  " + retCh.toString());
		return retCh;
	}
	
	public static void main(String[] args) {
		// to String
		Login c = new Login();
		c.setName(" Charity from Client 11");
		String json = new Login().toJson(c);		
		
		Login ch = new Login();
		ch.fromJson(json); 
		
	}

	
}


